package com.itheima.a01mymap;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class A02_MapDemo2 {
    public static void main(String[] args) {
        //创建集合
        Map<String, String> map = new HashMap<>();

        //添加元素
        map.put("郭靖", "黄蓉");
        map.put("尹志平", "小龙女");
        //map.put("郭靖", "黄蓉");

        //通过键找值进行遍历集合
        Set<String> keys = map.keySet();

        for (String key : keys) {
            String value = map.get(key);
            System.out.println(key + "--" + value);
        }

        //使用迭代器的方式进行遍历集合
        Iterator<String> it = keys.iterator();
        while (it.hasNext()) {
            String key = it.next();
            String value = map.get(key);
            System.out.println(key + "--" + value);
        }
    }
}
